import React from 'react';
import ReactDOM from 'react-dom/client';
import { i18nextReactInitConfig } from '@ijl/cli';
import i18next from 'i18next';

import App from './app';

export default () => <App/>;

const i18nextPromise = i18nextReactInitConfig(i18next);

export const mount = async (Сomponent, element = document.getElementById('app')) => {
  const root = ReactDOM.createRoot(element);
  await Promise.all([i18nextPromise]);
  root.render(<Сomponent/>);

  if(module.hot) {
    module.hot.accept('./app', async ()=> {
        await i18next.reloadResources();
        root.render(<Сomponent/>);
    })
  }
};

export const unmount = () => {
  ReactDOM.unmountComponentAtNode(document.getElementById('app'));
};

